package controller;

import com.alibaba.fastjson.JSON;
import dao.CarDAOImpl;
import entity.Car;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet("/get_car")
public class GetCarServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf8");
        resp.setContentType("application/json;charset=utf8");
        resp.setCharacterEncoding("utf8");

        //获取打印输出流,向网页输出内容
        PrintWriter writer = resp.getWriter();
        CarDAOImpl dao = new CarDAOImpl();
        int id=Integer.parseInt(req.getParameter("id"));
        Car car = dao.selectCarById(id);
        String json= JSON.toJSONString(car);

        writer.print(json);
        writer.close();
    }
}
